﻿namespace CSVParser
{
    using System.ComponentModel;
    using System.Runtime.Serialization;

    [DataContract]
    public class FieldMapping : INotifyPropertyChanged
    {
        #region Fields

        private string csvColumnName;
        private string destinationColumn;
        private string destinationColumnType;
        private int index;
        private bool isKeyColumn;
        private PropertyChangedEventHandler propertychanged;
        private FieldTransformation transformation;

        #endregion Fields

        #region Events

        event PropertyChangedEventHandler INotifyPropertyChanged.PropertyChanged
        {
            add { this.propertychanged += value; }
            remove { this.propertychanged -= value; }
        }

        #endregion Events

        #region Properties

        [DataMember]
        public string CsvColumnName
        {
            get { return csvColumnName; }
            set { csvColumnName = value; OnPropertyChanged("CsvColumnName"); }
        }

        [DataMember]
        public string DestinationColumn
        {
            get { return destinationColumn; }
            set { destinationColumn = value; OnPropertyChanged("DestinationColumn"); }
        }

        [DataMember]
        public string DestinationColumnType
        {
            get { return destinationColumnType; }
            set { destinationColumnType = value; OnPropertyChanged("DestinationColumnType"); }
        }

        [DataMember]
        public int Index
        {
            get{return index;}
            set { index = value; OnPropertyChanged("Index"); }
        }

        [DataMember]
        public bool IsKeyColumn
        {
            get { return isKeyColumn; }
            set { isKeyColumn = value; OnPropertyChanged("IsKeyColumn"); }
        }

        [DataMember]
        public FieldTransformation Transformation
        {
            get { return transformation; }
            set { transformation = value; OnPropertyChanged("Transformation"); }
        }

        #endregion Properties

        #region Methods

        public void OnPropertyChanged(string propertyname)
        {
            if (propertychanged != null)
            {
                this.propertychanged(this, new PropertyChangedEventArgs(propertyname));
            }
        }

        #endregion Methods
    }
}